import { def } from './utils.js';
import defineReative from './defineReative.js';
import { arrayMathods } from './array.js';
import observe from './observe.js';
import Dep from './Dep.js';

export default class Observer {
    constructor(value) {
        this.dep = new Dep();
        def(value, '__ob__', this, false);
        if (Array.isArray(value)) {
            Object.setPrototypeOf(value, arrayMathods);

        } else {
            this.walk(value);
        }
    }

    walk(value) {
        for (let key in value) {
            defineReative(value, key)
        }
    }

    // 数组的特殊遍历
    observeArray(array) {
        for (let item of array) {
            observe(item);
        }
    }
}